home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / docs / linux-do / programm / lpg-0.4 / lpg-0 / LPG / examples / ipc / fifoserver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-01  |  774 b   |  37 lines

  1. /*****************************************************************************
  2.  Excerpt from "Linux Programmer's Guide - Chapter 6"
  3.  (C)opyright 1994-1995, Scott Burkett
  4.  ***************************************************************************** 
  5.  MODULE: fifoserver.c
  6.  *****************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/stat.h>
  11. #include <unistd.h>
  12.  
  13. #include <linux/stat.h>
  14.  
  15. #define FIFO_FILE    "MYFIFO"
  16.  
  17. int main(void)
  18. {
  19.     FILE *fp;
  20.     char readbuf[80];
  21.  
  22.     /* Create the FIFO if it does not exist */
  23.     umask(0);
  24.     mknod(FIFO_FILE, S_IFIFO|0666, 0);
  25.  
  26.     while(1)
  27.     {
  28.         fp = fopen(FIFO_FILE, "r");
  29.         fgets(readbuf, 80, fp);
  30.         printf("Received string: %s\n", readbuf);
  31.         fclose(fp);
  32.     }
  33.  
  34.     return(0);
  35. }
  36.  
  37.